/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.l2jserver.gameserver.network.serverpackets;

import com.l2jserver.gameserver.instancemanager.CustomItemMallManager;
import com.l2jserver.gameserver.instancemanager.CustomItemMallManager.MallItem;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;

/**
 * @author ASUS
 *
 */
public class ExBrRecentProductList extends L2GameServerPacket {

	private L2PcInstance player;
	
	public ExBrRecentProductList(L2PcInstance player){
		this.player = player;
	}
	/* (non-Javadoc)
	 * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#writeImpl()
	 */
	@Override
	protected void writeImpl() {
		writeC(0xFE);
		writeH(0xDD);
		
		int historySize = player.getProductHistory().size();
		writeD(historySize);
		
		while(historySize>0){
			MallItem mItem = player.getProductHistory().get(historySize-1);
			writeD(mItem.getMallItemId());
			writeH(mItem.getCategory());
			writeD(mItem.getPoint());
			writeD(0);
			writeD(mItem.getSaleflag());
			writeD((int) (mItem.getStartTime() / 1000));
			writeD((int) (mItem.getEndTime() / 1000));
			writeC(127);
			writeC(mItem.getStartHour());
			writeC(mItem.getStartMin());
			writeC(mItem.getEndHour());
			writeC(mItem.getEndMin());
			writeD(mItem.getStock());
			writeD(mItem.getMaxStock());
			writeD(0);
			writeD(1);
			
			CustomItemMallManager.MallItemTemplate temp = mItem.getTemplate();
			int i = 0;
			for(CustomItemMallManager.MallItemTemplate.ItemPackage pk : temp.getItemPackage()){
				writeD(temp.getItemPackage().size() - i);
				writeD(pk.getItemId());
				writeD(pk.getCount());
				writeD(pk.getWeight());
				i++;
			}
			writeD(0);
			
			historySize--;
		}
	}

	/* (non-Javadoc)
	 * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#getType()
	 */
	@Override
	public String getType() {
		return "[S] FE:DD ExBrRecentProductList";
	}

}
